package com.mxx.v3.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mxx.v3.pojo.TQualityMouthQualified;
import com.mxx.v3.pojo.TQualityMouthQualifiedExample;
import com.mxx.v3.service.QualityMouthQualifiedService;
import com.mxx.v3.utils.PageQuery;
import com.mxx.v3.web.query.QualityMouthQualifiedQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.mxx.v3.dao.mapper.TQualityMouthQualifiedMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QualityMouthQualifiedImpl implements QualityMouthQualifiedService {

    @Autowired
    TQualityMouthQualifiedMapper tQualityMouthQualifiedMapper;
    @Override
    public PageInfo<TQualityMouthQualified> getData(PageQuery<QualityMouthQualifiedQuery> qualityMouthQualifiedQueryPageQuery) {
        // 设置分页拦截器
        Page<TQualityMouthQualified> tQualityMouthQualified = PageHelper.startPage(qualityMouthQualifiedQueryPageQuery.getPage(), qualityMouthQualifiedQueryPageQuery.getLimit(), true);
        //设置查询条件
        TQualityMouthQualifiedExample tQualityMouthQualifiedExample=new TQualityMouthQualifiedExample();
        TQualityMouthQualifiedExample.Criteria tQualityMouthQualifiedCriteria=tQualityMouthQualifiedExample.createCriteria();
        QualityMouthQualifiedQuery qualityMouthQualified=qualityMouthQualifiedQueryPageQuery.getQueryItem();
        //判断数据不为空
        if(!StringUtils.isEmpty(qualityMouthQualified.getWorkshop()))
        {
            tQualityMouthQualifiedCriteria.andWorkshopEqualTo(qualityMouthQualified.getWorkshop());
        }
        if(!StringUtils.isEmpty(qualityMouthQualified.getMonth()))
        {
            tQualityMouthQualifiedCriteria.andTimeLike(qualityMouthQualified.getMonth()+"%");
        }
        //从数据库中找寻对应数据
        List<TQualityMouthQualified> tQualityMouthQualifieds=tQualityMouthQualifiedMapper.selectByExample(tQualityMouthQualifiedExample);
       //组装数据，根据分页的大小来返回数据
        PageInfo<TQualityMouthQualified> pageInfo = new PageInfo<>(tQualityMouthQualifieds);
        pageInfo.setTotal(tQualityMouthQualified.getTotal());

        return pageInfo;
    }
}
